﻿// -----------------------------------------------------------------------
// <copyright file="ProfileTypeRequirementsListData.cs" company="VDC-IT" author="LTDUC">
//      Copyright (c) VDC-IT. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------

namespace VDC.VONE.DAL
{
    using System;
    using System.Collections.Generic;
    using System.Data.SqlClient;
    using System.Reflection;
    using Microsoft.ApplicationBlocks.Data;
    using VDC.COMMON;
    using VDC.VONE.ENTITIES;
    
    /// <summary>
    /// Class access to db ProfileTypeRequirementsList
    /// </summary>
    public class ProfileTypeRequirementsListData
    {
        /// <summary>
        /// Get ProfileTypeRequirementsList By Id
        /// </summary>
        /// <param name="profileTypeRequirementsListId">Param profileTypeRequirementsListId</param>
        /// <returns>Return ProfileTypeRequirementsList</returns>
        public ProfileTypeRequirementsListEN GetProfileTypeRequirementsListById(int profileTypeRequirementsListId)
        {
            string methodName = MethodBase.GetCurrentMethod().DeclaringType.ToString() + Constants.Dot + MethodBase.GetCurrentMethod().Name;
            LogHelper.Instance.WriteInfo(Constants.Begin + methodName);
            try
            {
                ProfileTypeRequirementsListEN profileTypeRequirementsList = null;
                var reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneProfileTypeRequirementsListGetById, profileTypeRequirementsListId);
                while (reader.Read())
                {
                    profileTypeRequirementsList = new ProfileTypeRequirementsListEN();

                    if (!reader.IsDBNull(0))
                    {
                        profileTypeRequirementsList.ProfileTypeRequirementsListId = reader.GetInt32(0);
                    }

                    if (!reader.IsDBNull(1))
                    {
                        profileTypeRequirementsList.RequirementsListId = reader.GetInt32(1);
                    }

                    if (!reader.IsDBNull(2))
                    {
                        profileTypeRequirementsList.ProfileTypeId = reader.GetInt32(2);
                    }
                }

                reader.Close();
                reader.Dispose();
                LogHelper.Instance.WriteInfo(Constants.End + methodName);
                return profileTypeRequirementsList;
            }
            catch (SqlException ex)
            {
                LogHelper.Instance.WriteError(methodName + Constants.Colon + ex.Message);
                throw new Exception(ex.ToString());
            }
        }

        /// <summary>
        /// Get list all ProfileTypeRequirementsList
        /// </summary>
        /// <returns>Return list all ProfileTypeRequirementsList</returns>
        public IList<ProfileTypeRequirementsListEN> GetProfileTypeRequirementsLists()
        {
            string methodName = MethodBase.GetCurrentMethod().DeclaringType.ToString() + Constants.Dot + MethodBase.GetCurrentMethod().Name;
            LogHelper.Instance.WriteInfo(Constants.Begin + methodName);
            try
            {
                IList<ProfileTypeRequirementsListEN> lstProfileTypeRequirementsList = new List<ProfileTypeRequirementsListEN>();
                SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneProfileTypeRequirementsListGetAll);
                while (reader.Read())
                {
                    ProfileTypeRequirementsListEN profileTypeRequirementsList = new ProfileTypeRequirementsListEN();

                    if (!reader.IsDBNull(0))
                    {
                        profileTypeRequirementsList.ProfileTypeRequirementsListId = reader.GetInt32(0);
                    }

                    if (!reader.IsDBNull(1))
                    {
                        profileTypeRequirementsList.RequirementsListId = reader.GetInt32(1);
                    }

                    if (!reader.IsDBNull(2))
                    {
                        profileTypeRequirementsList.ProfileTypeId = reader.GetInt32(2);
                    }

                    lstProfileTypeRequirementsList.Add(profileTypeRequirementsList);
                }

                reader.Close();
                reader.Dispose();
                LogHelper.Instance.WriteInfo(Constants.End + methodName);
                return lstProfileTypeRequirementsList;
            }
            catch (SqlException ex)
            {
                LogHelper.Instance.WriteError(methodName + Constants.Colon + ex.Message);
                throw new Exception(ex.ToString());
            }
        }

        /// <summary>
        /// Insert to db ProfileTypeRequirementsList
        /// </summary>
        /// <param name="profileTypeRequirementsList">Paarm ProfileTypeRequirementsList</param>
        /// <returns>Insert ProfileTypeRequirementsList</returns>
        public int Insert(ProfileTypeRequirementsListEN profileTypeRequirementsList)
        {
            string methodName = MethodBase.GetCurrentMethod().DeclaringType.ToString() + Constants.Dot + MethodBase.GetCurrentMethod().Name;
            LogHelper.Instance.WriteInfo(Constants.Begin + methodName);
            try
            {
                var sqlParameters = new[]
                                {
                                    new SqlParameter(Constants.SqlParamerterName.ProfileTypeRequirementsList.RequirementsListId, profileTypeRequirementsList.RequirementsListId),
                                    new SqlParameter(Constants.SqlParamerterName.ProfileTypeRequirementsList.ProfileTypeId, profileTypeRequirementsList.ProfileTypeId)
                                };

                var result = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneProfileTypeRequirementsListInsert, sqlParameters));
                LogHelper.Instance.WriteInfo(Constants.End + methodName);
                return result;
            }
            catch (SqlException ex)
            {
                LogHelper.Instance.WriteError(methodName + Constants.Colon + ex.Message);
                throw new Exception(ex.ToString());
            }
        }

        /// <summary>
        /// Update to db ProfileTypeRequirementsList
        /// </summary>
        /// <param name="profileTypeRequirementsList">Param ProfileTypeRequirementsList</param>
        public void Update(ProfileTypeRequirementsListEN profileTypeRequirementsList)
        {
            string methodName = MethodBase.GetCurrentMethod().DeclaringType.ToString() + Constants.Dot + MethodBase.GetCurrentMethod().Name;
            LogHelper.Instance.WriteInfo(Constants.Begin + methodName);
            try
            {
                var sqlParameters = new[]
                                {
                                    new SqlParameter(Constants.SqlParamerterName.ProfileTypeRequirementsList.ProfileTypeRequirementsListId, profileTypeRequirementsList.ProfileTypeRequirementsListId),
                                    new SqlParameter(Constants.SqlParamerterName.ProfileTypeRequirementsList.RequirementsListId, profileTypeRequirementsList.RequirementsListId),
                                    new SqlParameter(Constants.SqlParamerterName.ProfileTypeRequirementsList.ProfileTypeId, profileTypeRequirementsList.ProfileTypeId)
                                };

                SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneProfileTypeRequirementsListUpdate, sqlParameters);
                LogHelper.Instance.WriteInfo(Constants.End + methodName);
            }
            catch (SqlException ex)
            {
                LogHelper.Instance.WriteError(methodName + Constants.Colon + ex.Message);
                throw new Exception(ex.ToString());
            }
        }

        /// <summary>
        /// Delete ProfileTypeRequirementsList by profileTypeRequirementsListId
        /// </summary>
        /// <param name="profileTypeRequirementsListId">param profileTypeRequirementsListId</param>
        public void Delete(int profileTypeRequirementsListId)
        {
            string methodName = MethodBase.GetCurrentMethod().DeclaringType.ToString() + Constants.Dot + MethodBase.GetCurrentMethod().Name;
            LogHelper.Instance.WriteInfo(Constants.Begin + methodName);
            try
            {
                var sqlParameters = new[] 
                { 
                    new SqlParameter(Constants.SqlParamerterName.ProfileTypeRequirementsList.ProfileTypeRequirementsListId, profileTypeRequirementsListId)
                };

                SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneProfileTypeRequirementsListDelete, sqlParameters);
                LogHelper.Instance.WriteInfo(Constants.End + methodName);
            }
            catch (SqlException ex)
            {
                LogHelper.Instance.WriteError(methodName + Constants.Colon + ex.Message);
                throw new Exception(ex.ToString());
            }
        }

        /// <summary>
        /// Get List ProfileTypeRequirementsList By ProfileTypeId
        /// </summary>
        /// <param name="profileTypeId">Param profileTypeId</param>
        /// <returns>Return List ProfileTypeRequirementsList</returns>
        public IList<ProfileTypeRequirementsListEN> GetProfileTypeRequirementsListByProfileTypeId(int profileTypeId)
        {
            string methodName = MethodBase.GetCurrentMethod().DeclaringType.ToString() + Constants.Dot + MethodBase.GetCurrentMethod().Name;
            LogHelper.Instance.WriteInfo(Constants.Begin + methodName);
            try
            {
                IList<ProfileTypeRequirementsListEN> lstProfileTypeRequirementsList = new List<ProfileTypeRequirementsListEN>();
                var reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneProfileTypeRequirementsListGetByProfileTypeId, profileTypeId);
                while (reader.Read())
                {
                    ProfileTypeRequirementsListEN profileTypeRequirementsList = new ProfileTypeRequirementsListEN();

                    if (!reader.IsDBNull(0))
                    {
                        profileTypeRequirementsList.ProfileTypeRequirementsListId = reader.GetInt32(0);
                    }

                    if (!reader.IsDBNull(1))
                    {
                        profileTypeRequirementsList.RequirementsListId = reader.GetInt32(1);
                    }

                    if (!reader.IsDBNull(2))
                    {
                        profileTypeRequirementsList.ProfileTypeId = reader.GetInt32(2);
                    }

                    lstProfileTypeRequirementsList.Add(profileTypeRequirementsList);
                }

                reader.Close();
                reader.Dispose();
                LogHelper.Instance.WriteInfo(Constants.End + methodName);
                return lstProfileTypeRequirementsList;
            }
            catch (SqlException ex)
            {
                LogHelper.Instance.WriteError(methodName + Constants.Colon + ex.Message);
                throw new Exception(ex.ToString());
            }
        }

        /// <summary>
        /// Get List ProfileTypeRequirementsList By RequirementsListId
        /// </summary>
        /// <param name="requirementsListId">Param requirementsListId</param>
        /// <returns>Return List ProfileTypeRequirementsList</returns>
        public IList<ProfileTypeRequirementsListEN> GetProfileTypeRequirementsListByRequirementsListId(int requirementsListId)
        {
            string methodName = MethodBase.GetCurrentMethod().DeclaringType.ToString() + Constants.Dot + MethodBase.GetCurrentMethod().Name;
            LogHelper.Instance.WriteInfo(Constants.Begin + methodName);
            try
            {
                IList<ProfileTypeRequirementsListEN> lstProfileTypeRequirementsList = new List<ProfileTypeRequirementsListEN>();
                var reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneProfileTypeRequirementsListGetByRequirementsListId, requirementsListId);
                while (reader.Read())
                {
                    ProfileTypeRequirementsListEN profileTypeRequirementsList = new ProfileTypeRequirementsListEN();

                    if (!reader.IsDBNull(0))
                    {
                        profileTypeRequirementsList.ProfileTypeRequirementsListId = reader.GetInt32(0);
                    }

                    if (!reader.IsDBNull(1))
                    {
                        profileTypeRequirementsList.RequirementsListId = reader.GetInt32(1);
                    }

                    if (!reader.IsDBNull(2))
                    {
                        profileTypeRequirementsList.ProfileTypeId = reader.GetInt32(2);
                    }

                    lstProfileTypeRequirementsList.Add(profileTypeRequirementsList);
                }

                reader.Close();
                reader.Dispose();
                LogHelper.Instance.WriteInfo(Constants.End + methodName);
                return lstProfileTypeRequirementsList;
            }
            catch (SqlException ex)
            {
                LogHelper.Instance.WriteError(methodName + Constants.Colon + ex.Message);
                throw new Exception(ex.ToString());
            }
        }
    }
}